var app = getApp(), Toast = require("../../libs/zanui/toast/toast");

Page({
    data: {
        pages: 1,
        hide: !0,
        more: !0,
        refresh: !0
    },
    onLoad: function() {
        app.viewCount();
    },
    onShow: function() {
        var t = this;
        if (wx.getStorageSync("userInfo")) t.getMsgList(); else {
            var e = wx.getSystemInfoSync().windowHeight;
            t.setData({
                showLogin: !0,
                height: e
            });
        }
        app.util.footer(t);
    },
    getUserInfo: function(t) {
        var e = this;
        "getUserInfo:ok" == t.detail.errMsg ? (e.setData({
            showLogin: !1
        }), app.util.getUserInfo(function() {
            e.getMsgList();
        }, t.detail)) : wx.navigateTo({
            url: "../home/index"
        });
    },
    closeModal: function() {
        this.setData({
            showLogin: !1
        }), wx.navigateTo({
            url: "../home/index"
        });
    },
    getMsgList: function() {
        var e = this;
        app.util.request({
            url: "entry/wxapp/message",
            data: {
                act: "list",
                m: "superman_hand2"
            },
            success: function(t) {
                t.data.errno ? e.showIconToast(t.errmsg) : e.setData({
                    list: t.data.data,
                    total: t.data.data.length
                });
            }
        });
    },
    deleteItem: function(t) {
        var e = this, a = t.currentTarget.dataset.id;
        app.util.request({
            url: "entry/wxapp/message",
            cachetime: "0",
            data: {
                act: "delete",
                id: a,
                m: "superman_hand2"
            },
            success: function(t) {
                t.data.errno ? e.showIconToast(t.errmsg) : (e.showIconToast("删除成功", "success"), 
                e.getMsgList());
            }
        });
    },
    onReachBottom: function() {
        var s = this;
        if (s.data.refresh) if (s.data.total < 20) s.setData({
            more: !1
        }); else {
            s.setData({
                hide: !1
            });
            var o = s.data.pages + 1;
            app.util.request({
                url: "entry/wxapp/message",
                cachetime: "0",
                data: {
                    act: "list",
                    page: o,
                    m: "superman_hand2"
                },
                success: function(t) {
                    if (s.setData({
                        hide: !0
                    }), 0 == t.data.errno) {
                        var e = t.data.data;
                        if (0 < e.length) {
                            var a = s.data.list.concat(e);
                            s.setData({
                                total: e.length,
                                list: a,
                                pages: o
                            });
                        } else s.setData({
                            more: !1,
                            refresh: !1
                        });
                    } else s.showIconToast(t.errmsg);
                }
            });
        }
    },
    onPullDownRefresh: function() {
        this.getMsgList(), wx.stopPullDownRefresh();
    },
    showIconToast: function(t) {
        var e = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "fail";
        Toast({
            type: e,
            message: t,
            selector: "#zan-toast"
        });
    }
});